import React from "react";

import { Route, Redirect } from "react-router-dom";

import { isAuth } from "../../utils";

export default function AuthRoute({ component: Com, ...rest }) {  
  return (
    <Route
      {...rest}
      render={props => {
        if (isAuth()) {
          return <Com {...props} />;
        }

        // 未登录
        return (
          <Redirect
            to={{
              pathname: "/login",
              state: {
                from: props.location
              }
            }}
          />
        );
      }}
    />
  );
}
